public class BruteForce {
    public int[] productExceptSelf(int[] nums) {
        int n = nums.length;
        int[] answer = new int[n];
        for (int i = 0; i < n; i++) {
            int leftProduct = mul(nums, 0, i - 1);
            int rightProduct = mul(nums, i + 1, n - 1);
            answer[i] = leftProduct * rightProduct;
        }
        return answer;
    }

    public int mul(int[] nums, int i, int j) {//求i到j所有元素的乘积
        int product = 1;
        for (int k = i; k <= j; k++) {
            if (nums[k] == 0) {
                return 0;
            }
            product *= nums[k];
        }
        return product;
    }
}
